package cn.stylefeng.guns.modular.gridsystem.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.entity.BizThreholdItem;
import cn.stylefeng.guns.modular.gridsystem.model.param.BizThreholdItemParam;
import cn.stylefeng.guns.modular.gridsystem.service.BizThreholdItemService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 阈值配置项 控制器
 *
 * @author: ssy
 * @date: 2021/09/14 11:47
 */
@RestController
public class BizThreholdItemController {

    @Resource
    private BizThreholdItemService bizThreholdItemService;

    /**
     * 分页查询阈值配置项
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizThreholdItem/page")
    @BusinessLog(title = "阈值配置项_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(BizThreholdItemParam bizThreholdItemParam) {
        return new SuccessResponseData(bizThreholdItemService.page(bizThreholdItemParam));
    }

    /**
     * 获取全部阈值配置项
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizThreholdItem/list")
    @BusinessLog(title = "阈值配置项_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list() {
        return new SuccessResponseData(bizThreholdItemService.list());
    }

    /**
     * 查看详情阈值配置项
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizThreholdItem/detail")
    @BusinessLog(title = "阈值配置项_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(BizThreholdItemParam.detail.class) BizThreholdItemParam bizThreholdItemParam) {
        return new SuccessResponseData(bizThreholdItemService.detail(bizThreholdItemParam));
    }

    /**
     * 添加阈值配置项
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @PostMapping("/bizThreholdItem/add")
    @BusinessLog(title = "阈值配置项_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(BizThreholdItemParam.add.class) BizThreholdItemParam bizThreholdItemParam) {
        bizThreholdItemService.countByGIdAndChannel(bizThreholdItemParam);
        return new SuccessResponseData();

    }

    /**
     * 删除阈值配置项
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @PostMapping("/bizThreholdItem/delete")
    @BusinessLog(title = "阈值配置项_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(BizThreholdItemParam.delete.class) BizThreholdItemParam bizThreholdItemParam) {
        bizThreholdItemService.delete(bizThreholdItemParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑阈值配置项
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @PostMapping("/bizThreholdItem/edit")
    @BusinessLog(title = "阈值配置项_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(BizThreholdItemParam.delete.class) BizThreholdItemParam bizThreholdItemParam) {
        bizThreholdItemService.edit(bizThreholdItemParam);
        return new SuccessResponseData();
    }

    @GetMapping("/bizThreholdItem/threholdItemByChannelAndGatewayId")
    public BizThreholdItem threholdItemByChannelAndGatewayId(BizThreholdItemParam bizThreholdItemParam) {
        return bizThreholdItemService.threholdItemByChannelAndGatewayId(bizThreholdItemParam);
    }

}
